<template>
    <div>
        <el-container class="form-container">
            <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix">
                    <span>Demo</span>
                    <el-button type="primary" size="mini" style="float:right;padding: 6px 9px;" @click="submitForm">保存</el-button>
                </div>
                <div >
                   <el-form  :rules="rules"  ref="form"   :model="form" size="small" label-width="120px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item  label="名称" required prop="fdName">
                                    <el-input class="input" v-model="form.fdName" required ></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item  label="任务脚本" required prop="fdCronExpression">
                                    <el-popover v-model="cronPopover">
                                        <cron @change="changeCron" @close="cronPopover=false" i18n="cn"></cron>
                                        <el-input slot="reference" @click="cronPopover=true" v-model="form.fdCronExpression" placeholder="请输入定时策略"></el-input>
                                    </el-popover>
                                    <!-- <el-input class="input" v-model="form.fdCronExpression" required ></el-input> -->
                                </el-form-item>
                            </el-col>
                            </el-row>
                            <el-row>
                            <el-col :span="12">
                                <el-form-item  label="Bean名称" required prop="fdBeanName">
                                    <el-input class="input" v-model="form.fdBeanName" required ></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item  label="method名称" required prop="fdMethodName">
                                    <el-input class="input" v-model="form.fdMethodName" required ></el-input>
                                </el-form-item>
                            </el-col>
                            </el-row>
                            <el-row>
                            <el-col :span="12">
                                <el-form-item  label="参数"  prop="fdParam">
                                    <el-input class="input" v-model="form.fdParam"  ></el-input>
                                </el-form-item>
                            </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <el-form-item  label="描述"  prop="fdDescription">
                                        <el-input  type="textarea" class="input" v-model="form.fdDescription" style="width:85%"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                   </el-form>
                </div>
            </el-card>
        </el-container>
    </div>
</template>
<script>
import dateUtils from '@/utils/dateUtils';
import formUtils from '@/utils/formUtils';
import {cron} from 'vue-cron'
export default {
    name: "SysQuartzScheduleJobAdd",
    components: {
        cron
    },
    data() {
        return {
            form: {
                fdId:'',
                fdName:'',
                fdJobName:'',
                fdCronExpression:'',
                fdDescription:'',
                fdBeanName:'',
                fdMethodName:'excute',
                fdParam:'',
                fdType:''
            },
            rules:{
                fdName :[{required: true, message: '请输入名称', trigger: 'blur'}],
                fdJobName :[{required: true, message: '请输入任务名称', trigger: 'blur'}],
                fdCronExpression :[{required: true, message: '请输入任务脚本', trigger: 'blur'}],
                fdBeanName :[{required: true, message: '请输入Bean名称', trigger: 'blur'}],
                fdMethodName :[{required: true, message: '请输入method名称', trigger: 'blur'}],
            },
            cronPopover:false
        }
    },
    created() {
        this.initParam();
    },
    methods: {
        submitForm() {
          this.$refs['form'].validate((valid) => {
            if (valid) {
              this.fullscreenLoading = true;
              let forms = formUtils.convertToModel(this.form);
              this.$put('/api/sys/job/sys_quartz_schedule_job',forms).then((res) => {
                  this.fullscreenLoading = false;
                  if(res.status==1){
                      this.$message({
                          message: res.message,
                          type: 'success',
                          onClose:()=>{
                            this.$common.closeTag();
                          }
                      });
                  }else{
                      this.$message.error(res.message);
                  }
              });

            }
          });
        },
        changeCron(val) {
          this.form.fdCronExpression = val;
        },
        initParam() {
            let fdId = this.$route.query.id;
            if(formUtils.isNotEmpty(fdId)){
                this.fullscreenLoading = true;
                this.$fetch('/api/sys/job/sys_quartz_schedule_job',{
                    id:fdId
                }).then((res) => {
                    formUtils.convertToForm(res.data,this.form);
                    this.fullscreenLoading = false;
                });
            }
        }
    }
}
</script>
<style scoped >
@import "~@/assets/css/form.css";
</style>